//
//  TheTopView.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/9/27.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "TheTopView.h"
#import "Masonry.h"
#import "UIColor+CL.h"
#import "ZJLoopScrollView.h"

#define STYLE0 @"0" // 教务教学风格
#define STYLE1 @"1" // 学员端风格

@implementation TheTopView{
    ZJLoopScrollView *loopView;

}


-(void)WithStyle:(NSString *)style andDelegate:(id)delegate{
    
    _delegate = delegate;
//    _controller = (UIViewController *)delegate;
    
//    self = [super init];
//    if(self){
        self.backgroundColor = [UIColor redColor];
        
//        [_controller.view addSubview:self];
        
        if([style isEqualToString:STYLE0]){
        
            [self style];
        }else{
            [self style1];
        }
//    }
//    return self;
}

-(void)style{
    
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        NSString *StuName = [ud objectForKey:@"username"];
        NSString *roleNames = [ud objectForKey:@"roleNames"];

        if (StuName) {
            self.topBgNameLabel.text = StuName;
        }else{
            self.topBgNameLabel.text = @"李小明";
        }
        //     = @"李小明";
    
        if (roleNames) {
            self.topBgKindLabel.text = [NSString stringWithFormat:@"用户角色：%@",roleNames];
            [ud removeObjectForKey:@"roleNames"];
        }else{
            self.topBgKindLabel.text = [NSString stringWithFormat:@"用户角色：没取到"];
        }
//        self.topBgKindLabel.text = @"用户角色：教务老师";
        UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"often_into_small"]];
        [self.topBgView addSubview:iv];
        [iv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.topBgView.mas_centerY);
            make.right.equalTo(self.topBgView.mas_right).offset(-36/2);
        }];
        
    

}

-(UIImageView *)topBgView{ // 蓝色背景
    if (!_topBgView) {
        _topBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"edus_portrait_bg"]];
        [self.topView addSubview:_topBgView];
        [_topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topView.mas_top);
            make.left.equalTo(self.topView.mas_left);
            make.right.equalTo(self.topView.mas_right);
            make.height.equalTo(@(120/2));
        }];
    }
    
    
    return _topBgView;
}


-(UIImageView *)topBgIconView{ // 头像 Img
    if (!_topBgIconView) {
        _topBgIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"edus_portrait_normal"]];
        [self.topBgView addSubview:_topBgIconView];
        [_topBgIconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topView.mas_left).offset(36/2);
            make.centerY.equalTo(self.topBgView.mas_centerY);
            make.width.equalTo(@(40));
        }];
    }
    return _topBgIconView;
}

-(UILabel *)topBgNameLabel{ //  姓名
    if (!_topBgNameLabel) {
        _topBgNameLabel = [[UILabel alloc] init];
        [self.topBgView addSubview:_topBgNameLabel];
        _topBgNameLabel.textColor = [UIColor colorWithHex:0xffffff];
        [_topBgNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.topBgView.mas_centerY);
            make.right.equalTo(self.topView.mas_centerX);
            make.left.equalTo(self.topBgIconView.mas_right).offset(20/2);
            
        }];
        _topBgNameLabel.font = [UIFont systemFontOfSize:32/2];
    }
    return _topBgNameLabel;
}

-(UILabel *)topBgKindLabel{ //  用户角色
    if (!_topBgKindLabel) {
        _topBgKindLabel = [[UILabel alloc] init];
        _topBgKindLabel.textColor = [UIColor colorWithHex:0x1f7b8c];
        _topBgKindLabel.font = [UIFont systemFontOfSize:30/2];
        [self.topBgView addSubview:_topBgKindLabel];
        [_topBgKindLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.topBgView.mas_centerY);
            make.left.equalTo(self.topView.mas_centerX);
            make.right.equalTo(self.topView.mas_right).offset(-(32+36)/2);
        }];
        _topBgKindLabel.textAlignment = NSTextAlignmentRight;
    }
    return _topBgKindLabel;
}





-(UIView *)topView{ //  整个 视图 父试图
    if (!_topView) {
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = [UIColor colorWithHex:0xf5f8fa];
        
        
        [self addSubview:_topView];
        _topView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 134/2);
        
        
    }
    return _topView;
}


-(void)style1{
    //    self.topView;
    
    loopView = [[ZJLoopScrollView alloc] init];
    loopView.autoScroll = YES;
    loopView.imageArray = @[@"stu_see_banner",@"stu_see_banner",@"stu_see_banner"];
    
    
    [self addSubview:loopView];
    loopView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300/2);
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
